package 数据结构.章节09._148_双链表;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * @author 挚爱之夕
 * @date 2021/10/8 - 10 - 08 - 18:13
 * @Description: 数据结构.章节09._148_双链表
 * @Version: 1.0
 */
public class DoubleLinkedListTest {
    DoubleLinkedList<String> list = new DoubleLinkedList<String>();
    @Test
    @Before
    public void add() {
        list.add("a");
        list.add("b");
        list.add("c");
//        System.out.println(list.toString());
    }

    @Test
    public void delete() {
        list.delete("a");
        list.delete("a");
        Assert.assertEquals("b <-> c",list.toString());
    }

    @Test
    public void testDelete() {
        list.delete(2);
        Assert.assertEquals("a <-> b",list.toString());
        list.delete(0);
        Assert.assertEquals("b",list.toString());
        list.delete(0);
        Assert.assertEquals("",list.toString());
    }

    @Test
    public void modify() {
        list.modify(0,"love");
        Assert.assertEquals("love <-> b <-> c",list.toString());
    }

    @Test
    public void contains() {
        Assert.assertTrue(list.contains("a"));
    }

    @Test
    public void find() {
        Assert.assertEquals("a",list.find(0));
    }

    @Test
    public void testFind() {
        Assert.assertEquals(0,list.find("a"));
    }

    @Test
    public void testToString() {
        Assert.assertEquals("a <-> b <-> c",list.toString());
    }
    @Test
    public void iter(){
        while(list.hasNext()){
            System.out.println(list.next());
        }
    }
}